package com.bw.gmali_logger.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

//@RestController = @Controller+@ResponseBody
@RestController //表示返回普通对象而不是页面
@Slf4j
public class LoggerController {
   @Resource
    private KafkaTemplate<String, String> kafkaTemplate;

    @RequestMapping("test1")
// @ResponseBody
    public String test1() {
        System.out.println("11111111");
        return "success";
    }


    @RequestMapping("test2")
    public String test2(@RequestParam("name") String name,
                        @RequestParam("age") int age) {
        System.out.println(name + ":" + age);
        return "success";
    }

@RequestMapping("applog")
public String  getLogger(@RequestParam("param") String jsonStr) {

    //测试数据流
    System.out.println(jsonStr);

//将数据落盘，可以使用日志打印的形式写到磁盘中
    log.info(jsonStr);

    //将数据写入Kafka
    kafkaTemplate.send("ods_base_log", jsonStr);


    return "success";


}
}
